package com.abel.quiz.security;

import com.abel.quiz.common.vo.AjaxResp;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @param
 * @author abel.lin
 * @description
 * @date_time 2017/8/7 11:10
 * org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint
 */
public class MyLoginUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
						 AuthenticationException authException) throws IOException,
			ServletException {

		if (AjaxResp.isAjax(request)) {
			AjaxResp resp = new AjaxResp(AjaxResp.CodeArgs.NO);
			resp.toWriter(response);
		} else {
			super.commence(request, response, authException);
		}

	}
}
